package com.ftg.shopping.sp_deptinfo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.sp_deptinfo.entity.Sp_deptinfo;
import com.ftg.shopping.sp_deptinfo.mapper.Sp_deptinfoMapper;
import com.ftg.shopping.sp_deptinfo.service.Sp_deptinfoService;
import com.oracle.jrockit.jfr.ValueDefinition;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "部门维护")
@RestController
@RequestMapping("/api/sp_deptinfo")
public class Sp_deptinfoController {

    @Autowired
    Sp_deptinfoService deptinfoService;

    @ApiOperation("查看全部数据")
    @GetMapping("/list")
    public List<Sp_deptinfo> list(){
        return deptinfoService.list();
    }

    @ApiOperation("按主键查询一个部门")
    @GetMapping("/findone/{deptno}")
    public Sp_deptinfo list(@ApiParam("主键")@PathVariable int deptno){
        return deptinfoService.findone(deptno);
    }

    @ApiOperation("分页查询带模糊(模糊条件是部门编号)")
    @GetMapping("page1")
    public IPage<Sp_deptinfo> list1(@RequestParam int page,@RequestParam int limit,@RequestParam(required = false)  String deptno){
        return deptinfoService.testPage1(page,limit,deptno);
    }


    @ApiOperation("添加部门信息")
    @PostMapping("/save")
    public int saveSp_deptinfo( Sp_deptinfo d ){
        return deptinfoService.insert(d);
    }

    @ApiOperation("修改部门信息")
    @PostMapping("/update")
    public int updateSp_deptinfo( Sp_deptinfo d){
        return deptinfoService.updateSp_deptinfo(d);
    }




    @ApiOperation("按主键删除部门")
    @PostMapping("/del")
    public  int delSp_deptinfo( int deptno){
        return deptinfoService.del1(deptno);
    }

        @ApiOperation("layui分页查询带模糊")
        @GetMapping("/page2")
        public LayuiPage<Sp_deptinfo> page2(@RequestParam int page,@RequestParam int limit,@RequestParam(required = false) String dname){
               return deptinfoService.layuipage(page,limit,dname);
    }
}
